package com.janal.model.Basedao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Basedao {
    //查询操作
    public static ResultSet execute(Connection conn,String sql,Object[] params,ResultSet rs,PreparedStatement pstm) throws Exception{
        pstm = conn.prepareStatement(sql);
        for(int i = 0; i < params.length; i++){
            pstm.setObject(i+1, params[i]);
        }
        rs = pstm.executeQuery();
        return rs;
    }

    //更新操作
    public static int execute(Connection connection,String sql,Object[] params,PreparedStatement pstm) throws Exception{
        int updateRows = 0;
        pstm = connection.prepareStatement(sql);
        for(int i = 0; i < params.length; i++){
            pstm.setObject(i+1, params[i]);
        }
        updateRows = pstm.executeUpdate();
        return updateRows;
    }
}
